<template>
  <view class="upload_img_comp">
    <u-upload
      ref="uUpload"
      :before-remove="beforeRemove"
      :action="action"
      :file-list="fileList"
      :max-count="maxCount"
      :show-progress="false"
      :header="header"
      :form-data="formData"
      @on-uploaded="onSuccess"
    ></u-upload>
  </view>
</template>

<script>
import Config from '@/config/config.conf';
export default {
  components: {},
  props: {
    fileList: {
      // 默认文件列表
      type: Array,
      default: () => []
    },
    maxCount: {
      // 最大数量
      type: Number,
      default: 1
    },
    channelId: {
      type: [Number, String],
      default: ''
    }
  },
  data() {
    return {
      formData: {
        channel_id: this.channelId
      },
      header: {
        token: this.$store.state.user.token
      },
      action: ''
    };
  },
  created() {
    this.action = (process.env.NODE_ENV === 'development' ? 'http://zsgh.center999.com/' : Config.domain) + 'api/common/nupload';
  },
  methods: {
    upload() {
      this.$refs.uUpload.upload();
    },
    onSuccess(e) {
      // 上传成功
      console.log(e);
      this.$emit('uploadSuccess', e);
    },
    beforeRemove() {
      // console.log(123)
      // 删除图片前操作, 如果返回false，终止移除操作, 如果返回true，执行移除操作
      return false;
    }
  }
};
</script>

<style scoped lang="scss">
.upload_img_comp {
}
</style>
